package com.ourteam.frame.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ourteam.frame.web.ProgressInfoBean;

@Controller
@RequestMapping("/common")
public class CommonController extends AbstractServiceController {

	@RequestMapping("/setParam")
	@ResponseBody
	public void setParam(@RequestParam String key, @RequestParam String value, HttpServletRequest request, Model model)
			throws Exception {

		request.getSession().setAttribute(key, value);

	}

	@RequestMapping("/getParam")
	@ResponseBody
	public String setParam(@RequestParam String key, HttpServletRequest request, Model model) throws Exception {

		return (String) request.getSession().getAttribute(key);

	}

	@RequestMapping("/getLocalMessage")
	@ResponseBody
	public String getLocalMessage(@RequestParam String key, HttpServletRequest request, Model model) throws Exception {

		return getLocalMessage(key, request.getLocale());

	}

	@RequestMapping("/checkJobProgress")
	@ResponseBody
	public ProgressInfoBean checkProgress(@RequestParam String progressId, final HttpServletRequest request)
			throws Exception {

		return (ProgressInfoBean) request.getSession().getAttribute(progressId);

	}
	
	@RequestMapping("/getConfig")
	@ResponseBody
	public String getConfig(@RequestParam String key) throws Exception {
		return super.getConfig(key);
	}
	
	@RequestMapping("/getSessionId")
	@ResponseBody
	public String getSessionId(HttpServletRequest request) throws Exception {
		return request.getSession().getId();
	}
	
	
}
